package cn.iocoder.yudao.module.robot.controller.admin.callrecord;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;


import cn.iocoder.yudao.module.robot.controller.admin.callrecord.vo.*;
import cn.iocoder.yudao.module.robot.dal.dataobject.callrecord.RobotCallRecordDO;
import cn.iocoder.yudao.module.robot.service.callrecord.RobotCallRecordService;

@Tag(name = "管理后台 - 机器人通话记录")
@RestController("RobotCallRecordController")
@RequestMapping("/robot/call-record")
@Validated
public class RobotCallRecordController {

    @Resource
    private RobotCallRecordService robotCallRecordService;

    @PostMapping("/create")
    @Operation(summary = "创建机器人通话记录")
    @PreAuthorize("@ss.hasPermission('robot:call-record:create')")
    public CommonResult<Long> createCallRecord(@Valid @RequestBody CallRecordSaveReqVO createReqVO) {
        return success(robotCallRecordService.createCallRecord(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新机器人通话记录")
    @PreAuthorize("@ss.hasPermission('robot:call-record:update')")
    public CommonResult<Boolean> updateCallRecord(@Valid @RequestBody CallRecordSaveReqVO updateReqVO) {
        robotCallRecordService.updateCallRecord(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除机器人通话记录")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('robot:call-record:delete')")
    public CommonResult<Boolean> deleteCallRecord(@RequestParam("id") Long id) {
        robotCallRecordService.deleteCallRecord(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得机器人通话记录")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('robot:call-record:query')")
    public CommonResult<CallRecordRespVO> getCallRecord(@RequestParam("id") Long id) {
        RobotCallRecordDO callRecord = robotCallRecordService.getCallRecord(id);
        return success(BeanUtils.toBean(callRecord, CallRecordRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得机器人通话记录分页")
    @PreAuthorize("@ss.hasPermission('robot:call-record:query')")
    public CommonResult<PageResult<CallRecordRespVO>> getCallRecordPage(@Valid CallRecordPageReqVO pageReqVO) {
        PageResult<RobotCallRecordDO> pageResult = robotCallRecordService.getCallRecordPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, CallRecordRespVO.class));
    }



}